
import { _decorator, Component, Node } from 'cc';
import { CardReverser } from './CardReverser';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = Switch
 * DateTime = Wed Feb 02 2022 18:14:38 GMT+0800 (中国标准时间)
 * Author = awi1299
 * FileBasename = Switch.ts
 * FileBasenameNoExtension = Switch
 * URL = db://assets/script/Switch.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */

@ccclass('Switch')
export class Switch extends Component {
    // [1]
    // dummy = '';

    // [2]
    // @property
    // serializableDummy = 0;

    /**
     * 是否给大家看
     */
    isPublic = true

    @property(Node)
    content: Node | null = null

    start() {
        this.node.on(Node.EventType.TOUCH_END, this.swapPublicPrivate, this);
    }

    swapPublicPrivate() {
        this.isPublic = !this.isPublic
        const cards: CardReverser[] = this.content.getComponentsInChildren(CardReverser)
        cards.forEach(card => {
            if (!card.isExpose && this.isPublic) {
                card.toBack()
            }
            if (!card.isExpose && !this.isPublic) {
                card.toFront()
            }
        });
    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
